/**
 * @author yxw
 * date : 2013年10月31日 下午10:09:57 
 */
package com.tzinfo.tzt.activity.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

public class MarkerTools {
	public static Drawable drawTextAtBitmap(Bitmap bitmap, String text,int size) {
		int x = bitmap.getWidth();
		int y = bitmap.getHeight(); // 创建一个和原图同样大小的位图
		Bitmap newbit = Bitmap.createBitmap(x, y, Bitmap.Config.ARGB_8888);
		Canvas canvas = new Canvas(newbit);
		Paint paint = new Paint(); // 在原始位置0，0插入原图
		canvas.drawBitmap(bitmap, 0, 0, paint);
		paint.setColor(Color.parseColor("#FFFFFF"));
		paint.setTextSize(size);
		//居中处理
		Rect textBounds = new Rect();
		paint.getTextBounds(text, 0, text.length(), textBounds);
		int textHeight = textBounds.bottom - textBounds.top;
		int textWidth = textBounds.right - textBounds.left;
		
		canvas.drawText(text, (x-textWidth)/2, (int)((y-textHeight)/1.3), paint);// 在原图指定位置写上字
		canvas.save(Canvas.ALL_SAVE_FLAG); // 存储
		canvas.restore();
		Drawable drawable=(Drawable) new BitmapDrawable(newbit);
		return drawable;
	}
}
